<template>
	<view class="bg min100 plr-30 pt-40">
		<view class="size-40 gray mb-30">
			填写实名认证信息
		</view>
		<view class="gray-2 size-22 mb-40">
			<view class="mb-20">
				您的实名认证信息将用于完成必要的安全检查，以提升你的帐号安全性。
			</view>
			<view class="">
				证件信息绑定后将不能修改，请填写本人实名信息，如非本人实名将无法提现，账号丢失也将无法找回账号。
			</view>
		</view>
		<view class="bg radius-20 plr-30">
			<u-field v-model="info.name" :disabled="info.is_auth==1" label="真实姓名" placeholder-style="color:#999"
				placeholder="请输入您的真实姓名">
			</u-field>
			<u-field v-model="info.card" :disabled="info.is_auth==1" label="身份证号" placeholder-style="color:#999"
				:border-bottom="false" placeholder="请输入您的身份证号码">
			</u-field>
			
			<u-field v-model="info.code" :disabled="info.is_auth==1" v-if="info.is_auth==0" label="验证码" placeholder-style="color:#999"
				:border-bottom="false" placeholder="请输入验证码">
				<view slot="right" class="getBtn ptb-12 plr-16 red" @click="getcode">
					{{vscode}}
				</view>
			</u-field>
		</view>
		<u-button type="primary" class="mt-60" hover-class="none" :disabled="info.is_auth==1" @click="userAuth">提交</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				vscode: '获取验证码',
			}
		},
		onShow() {
			this.init();
		},
		methods: {
			init() {
				this.$http('api/user/userInfo').then(res => {
					this.info = res;
				})
			},
			// 获取验证码
			getcode() {
				if (this.vscode != "获取验证码" && this.vscode != "重新发送") {
					return
				}
				this.countNum = 60
				this.countDownTimer = setInterval(() => {
					if (this.countNum < 1) {
						clearInterval(this.countDownTimer)
						this.countDownTimer = null
						this.vscode = "重新发送";
						return;
					}
					this.countNum--;
					this.vscode = this.countNum + '秒重发';
				}, 1000)
				this.$http('api/user/userAuthCode', {
					// phone: uni.getStorageSync('phone'),
					// type: 1
				}, 'POST').then(data => {
					uni.showToast({
						title: "发送成功",
						icon: 'none'
					})
				}).catch(() => {
					clearInterval(this.countDownTimer)
					this.countDownTimer = null
					this.vscode = "获取验证码";
				})
			},
			userAuth() {
				if (this.info.name == '') {
					uni.showToast({
						title: "请输入真实姓名!",
						icon: 'none'
					})
					return;
				}
				if (this.info.card == '') {
					uni.showToast({
						title: "请输入身份证号!",
						icon: 'none'
					})
					return;
				}
				if (this.info.code == '') {
					uni.showToast({
						title: "请输入验证码!",
						icon: 'none'
					})
					return;
				}
				this.$http('api/user/userAuth', {
					name: this.info.name,
					card: this.info.card,
					code: this.info.code
				}, "POST").then(res => {
					uni.showToast({
						title: "提交成功!"
					})
					setTimeout(() => {
						uni.navigateTo({
							url: './editUser'
						})
					}, 500)
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	page{
		background-color: #F5F5F5;
	}
	::v-deep  .u-field {
		color: #333 !important;
		font-size: 26rpx;
	}

	::v-deep  .u-btn--primary--disabled {
		background: #DEE4E8 !important;
	}
</style>
